package com.dlwx.parttimetalent.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.bean.ClassIntentListBean;
import com.dlwx.parttimetalent.comm.Constant;
import com.dlwx.parttimetalent.ui.AttentionUser2Activity;
import com.dlwx.parttimetalent.utils.SPUtils;

/**
 * Created by Administrator on 2017/11/21.
 */

public class AttentionClassifyAdapter extends ListBaseAdapter<ClassIntentListBean.BodyBean> {
    private  Context context;
    private int userId;
    public AttentionClassifyAdapter(Context context) {
        super(context);
        this.context=context;
        userId= (int) SPUtils.get(context, Constant.USER_ID,0);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_attention_classify;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        final ClassIntentListBean.BodyBean bean = getDataList().get(position);
        TextView tvName=holder.getView(R.id.tv_name);
        TextView tv_money=holder.getView(R.id.tv_money);
        TextView tvGrade=holder.getView(R.id.tv_grade);
        TextView tvComment=holder.getView(R.id.tv_comment);
        TextView tv_good_comment=holder.getView(R.id.tv_good_comment);
        TextView tv_boss=holder.getView(R.id.tv_boss);
        TextView tv_percent=holder.getView(R.id.tv_percent);
        TextView tv_label=holder.getView(R.id.tv_label);
        TextView tv_label_remark=holder.getView(R.id.tv_label_remark);
        TextView tv_server=holder.getView(R.id.tv_server);
        TextView tv_confirm=holder.getView(R.id.tv_confirm);
        tvName.setText(bean.getClassname());
        tvGrade.setText(bean.getScore()+"分");
        tvComment.setText(bean.getPjnum()+"条评价");
        tv_good_comment.setText(bean.getGodrate()+"%的主顾好评");
        tv_boss.setText(bean.getGynum()+"个主人雇佣过");
        tv_percent.setText("接单率"+bean.getMonorate()+"%");
        tv_label.setText(bean.getLabelname());
        if(bean.getLabeltime()==1){
            tv_label_remark.setText("（"+bean.getMintime()+"天起）");
        }else{
            tv_label_remark.setText("（"+bean.getMintime()+"小时起）");
        }
        tv_money.setText(context.getString(R.string.rmb)+bean.getLabelprice());
        tv_server.setText("简介说明："+bean.getLabelcontent());
        if(bean.getStart()==1){
            tv_confirm.setBackground(ContextCompat.getDrawable(context,R.drawable.bg_red_confirm));
        }else{
            tv_confirm.setBackground(ContextCompat.getDrawable(context,R.drawable.bg_grey_confirm));
        }
        if(TextUtils.equals(bean.getListid()+"",userId+"")){
            tv_confirm.setText("修改/添加");
        }else{
            tv_confirm.setText("下单");
        }
        tvComment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(context,AttentionUser2Activity.class);
                i.putExtra("listId", bean.getListid()+"");
                i.putExtra("isScroll",true);
                context.startActivity(i);
            }
        });
    }
}
